package com.lj.job.result;

import com.lj.job.entity.ScheduleJob;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * <p>
 * 定时任务 分页结果
 * </p>
 *
 * @author luojing
 * @since 2025-03-20 15:23:28
 */
@Data
@Schema(description = "定时任务 分页结果")
public class JobPageResult {

    private Long id;

    @Schema(description = "执行bean的名称 ")
    private String beanName;

    @Schema(description = "执行参数 ")
    private String params;

    @Schema(description = "cron表达式 ")
    private String cronExpression;

    @Schema(description = "任务状态 参考字典: ScheduleJobStatus")
    private Integer status;

    @Schema(description = "备注 ")
    private String remark;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    public static JobPageResult of(ScheduleJob entity) {
        if (entity == null) {
            return null;
        }
        JobPageResult result = new JobPageResult();
        result.setId(entity.getId());
        result.setBeanName(entity.getBeanName());
        result.setParams(entity.getParams());
        result.setCronExpression(entity.getCronExpression());
        result.setStatus(entity.getStatus().getValue());
        result.setRemark(entity.getRemark());
        result.setCreateTime(entity.getCreateTime());
        result.setUpdateTime(entity.getUpdateTime());
        return result;
    }
}
